<template>
	<view class="close-order">{{time}}后订单将自动取消</view>
</template>

<script>
	export default{
		data(){
			return{
				remainder: 450,
				timer: null
			}
		},
		props: {
			info: {
				type: Object,
				default: ()=>{}
			}
		},
		mounted() {
			// 开始倒计时
			this.startCountDown()
		},
		computed:{
			time(){
				let minute = Math.floor(this.remainder / 60)
				let second = this.remainder % 60
				if(minute < 10)minute = '0' + minute
				if(second < 10)second = '0' + second
				return `${minute}:${second}`
			}
		},
		methods: {
			startCountDown(){
				let curTime = new Date().getTime()
				curTime = Math.floor(curTime / 1000)
				this.remainder = this.info.createtime - curTime  + 180
				console.log(this.info.createtime- curTime);
				this.timer = setInterval(()=>{
					if(this.remainder <= 1){
						clearInterval(this.timer)
						this.$emit('done')
					}else{
						this.remainder -= 1
					}
				}, 1000)
			},
			destory(){
				clearInterval(this.timer)
			}
		},
	}
</script>

<style scoped lang="scss">
	.close-order{
		background-color: #FFF4DF;
		padding: 20rpx ;
		font-size: 22rpx;
		color: #333333;
		@extend .flex-center;
	}
</style>